package me.ydq.spring;

import me.ydq.DynamicQuery;
import me.ydq.convert.ColumnConvert;
import me.ydq.convert.TableConvert;
import me.ydq.dialect.Dialect;
import me.ydq.mapper.RowMapperProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;

@AutoConfiguration
@ConditionalOnBean(NamedParameterJdbcTemplate.class)
public class DynamicQueryAutoConfiguration {

    @Bean
    @ConditionalOnMissingBean
    public DynamicQuery dynamicQuery(NamedParameterJdbcTemplate namedParameterJdbcTemplate,
                                     @Autowired(required = false) Dialect dialect,
                                     @Autowired(required = false) TableConvert tableConvert,
                                     @Autowired(required = false) ColumnConvert columnConvert,
                                     @Autowired(required = false) RowMapperProvider rowMapperProvider) {
        return DynamicQuery.of(namedParameterJdbcTemplate, dialect, tableConvert, columnConvert, rowMapperProvider);
    }
}
